package be.rubengerits.bluetooth.tester;

import java.io.File;

import be.rubengerits.bluetooth.tester.filepicker.FilePickerDialogFragment;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.*;

public class MainActivity extends Activity implements FilePickerDialogFragment.FilePickerDialogListener {

	private TextView textValue;

	private TextView fileValue;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
		
		textValue = (TextView) findViewById(R.id.text_value);
		fileValue = (TextView) findViewById(R.id.file_value);
    }

	public void showFilePickerDialog(View view) {
		FilePickerDialogFragment dialog = new FilePickerDialogFragment();
		dialog.show(getFragmentManager(), "file_picker");
	}

	@Override
	public void onDialogPositiveClick(DialogFragment dialog, File file) {
		fileValue.setText(file.getAbsolutePath());
	}
	
	@Override
	public void onDialogNegativeClick(DialogFragment dialog) {
	}
	
	public void sendText(View view) {
		try {
			//BluetoothUtil.sendText("", textValue.getText().toString());
			
			Toast.makeText(view.getContext(), textValue.getText(), 50).show();
		} catch (Exception e) {
			Toast.makeText(view.getContext(), e.getMessage(), 50).show();
		}
	}
	
	public void sendFile(View view) {
		try {
			File f = new File(fileValue.getText().toString());
			
			Toast.makeText(view.getContext(), f.getName(), 50).show();
		} catch (Exception e) {
			Toast.makeText(view.getContext(), e.getMessage(), 50).show();
		}
	}
}
